import * as bm from "/js/baseModule.js";
let Clipboard = require("/js/clipboard.js");

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        var that = this;
        that.feedData = {};
        that.hasReason;
        funs.getModuleFuns('modules/project/FeedbackDemand.js', function (mod) {
            $.extend(true, that.feedData, mod.getData());
        });

        that.vue = new Vue({
            el: '.FeedbackCancel_vue',
            data: {
                current_demand: globalData.current_demand,
                feedback_data: that.feedData,
            },
            computed: {
                oneDay: function () {
                    let startTime = globalData.current_demand.bid_win_at;
                    let stime = startTime * 1000;
                    let date = new Date().getTime();
                    let gapMin = Math.floor((date - stime) / 1000 / 60);
                    if (gapMin <= 0) {
                        //防止偶尔出现的js取时间不准确
                        gapMin = 1;
                    }

                    if (gapMin > (60 * 24)) {
                        return false;
                    }
                    return true;
                },
            }
        });

        that.wxTip = that.find(".tip-copy");
        /*一键复制插件初始化实例*/
        var clipboard = new Clipboard('.wx-code').on('success', function (e) {
            var e = e || window.event;
            console.log(e);
            that.wxTip.show();
            setTimeout(function () {
                that.wxTip.hide();
            }, 2000);
        }).on('error', function (e) { });
    }

    /**进入反馈提交页*/
    _evt_feedbackReason(obj, hit) {
        var that = this;
        var hasReason = parseInt($(hit).attr("has-reason"));
        funs.swipeModule('modules/project/FeedbackReason.js', '100%', 'left', function (mod) {
            mod.setReason(hasReason, that.feedData);
        }, true)
    }

    _evt_chooseTab(obj, hit) {
        this.vue.tabType = $(hit).attr('type');
        this.find('.pull-right').removeClass('icon-checkmark');
        if (this.vue.tabType == 'other' && this.vue.text.trim().length > 0) {
            this.find(".btn").removeAttr("disabled");
            return;
        }
        this.find(".btn").attr("disabled", "false");
    }

    /**options展开收回*/
    _evt_optionsShown(obj, hit) {
        $(obj).find('.icon-circle-down').toggleClass('rotate');
        $(obj).parent().find('.options').slideToggle(300);
    }

    // 单选原因
    _evt_clickType(obj, hit) {
        let cur = $(hit).find('.pull-right');
        let type = $(hit).attr('type');
        this.updateType(type);
    }

}
